#include <iostream>
#include <vector>

using namespace std;


// Definition for singly-linked list.
struct ListNode {
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};


class Solution {
public:
    bool isPalindrome(ListNode* head) {
        vector<ListNode*> list;
        while (head != nullptr){
            list.push_back(head);
            head = head->next;
        }
        int j = list.size() - 1;
        int i = 0;
        bool flag =true;
        while (i < j){
            if (list[i]->val != list[j]->val) {
                return false;
            }
            else {
                i++;
                j--;
            }
        }
        return true;
    }

};